<template>
  <div class="contain-body hdda-box">
    <Title></Title>
    <div class="search-contain-body">
      <el-form ref="form"
               inline
               :model="form"
               label-width="75px">
        <el-form-item>
          <div class="d-ib font-table"
               slot="label">姓名：</div>
          <el-input v-model="form.xms"></el-input>
        </el-form-item>

        <el-form-item>
          <div class="d-ib font-table"
               slot="label">警员编号：</div>
          <el-input v-model="form.jybhs"></el-input>
        </el-form-item>

        <el-form-item>
          <el-button icon="el-icon-search"
                     class="button-search"
                     @click="onSubmit">搜索</el-button>
        </el-form-item>
      </el-form>

    </div>
    <div>
      <div class="pos-r">
        <Title msg="信息列表"></Title>
        <div class="pos-a" style="right: 0">
          <el-button @click="openOptions('','add')" type="primary" icon="el-icon-plus">
            新增
          </el-button>
        </div>
      </div>
      <CustomTable :columns="columns"
                   :table-data="tableData"
                   :pagination="pagination"
                   @pagination="paginationChange"
                   :total="total">
        <div slot="options"
             slot-scope="scope">
          <el-button @click="openOptions(scope,'details')" style="margin-left: 4px;" class="button-blur">详情</el-button>
          <el-button @click="openOptions(scope,'edit')" style="margin-left: 4px;" class="button-green">编辑</el-button>
          <el-button @click="deleteDate(scope)" style="margin-left: 4px;" class="button-red">删除</el-button>
        </div>
      </CustomTable>
    </div>

    <el-dialog width="819px"
               center
               class="custom-dialog-fill font-table"
               title="活动审批"
               :visible.sync="dialog.open">

      <div class="dialog-title"
           slot="title">
        {{ dialog.title }}
      </div>

      <div class="d-f jc-c">

        <el-form :disabled="flag" class="font-table" style="color: #000000;"ref="form" :model="form" label-width="75px">
          <div class="mb-14">
            <b>基本信息</b>
          </div>
          <el-form-item>
            <div class="d-ib font-table" slot="label">姓  名：</div>
            <el-input v-model="form.xm" style="width: 180px"></el-input>
            <div class="d-ib font-table"style="margin-left: 40px">执勤区域：</div>
            <el-input v-model="form.zqqy" style="width: 180px"></el-input>
          </el-form-item>
          <el-form-item>
            <div class="d-ib font-table" slot="label">年  龄：</div>
            <el-input v-model="form.nl" style="width: 180px"></el-input>
            <div class="d-ib font-table" style="margin-left: 68px">民族：</div>
            <el-select v-model="form.mzdm" style="width: 180px" placeholder="请选择民族" filterable>
              <el-option label="" value="">--请选择民族--</el-option>
              <el-option
                      v-for="item in optionsMz"
                      :key="item.value"
                      :label="item.content"
                      :value="item.id">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item>
            <div class="d-ib font-table" slot="label">警  龄：</div>
            <el-input v-model="form.jl" style="width: 180px"></el-input>
            <div class="d-ib font-table" style="margin-left: 40px">警员编号：</div>
            <el-input v-model="form.jybh"style="width: 180px"></el-input>
          </el-form-item>

          <el-form-item>
            <div class="d-ib font-table" slot="label">国  籍：</div>
            <el-select v-model="form.gjdm" style="width: 180px" placeholder="请选择国籍" filterable>
              <el-option label="" value="">--请选择国籍--</el-option>
              <el-option
                      v-for="item in optionsGj"
                      :key="item.value"
                      :label="item.content"
                      :value="item.id">
              </el-option>
            </el-select>
            <div class="d-ib font-table"style="margin-left: 68px">性别：</div>
            <el-select v-model="form.xbdm" style="width: 180px"  placeholder="请选择性别">
              <el-option label="" value="">--请选择性别--</el-option>
              <el-option
                      v-for="item in optionsXb"
                      :key="item.value"
                      :label="item.content"
                      :value="item.id">
              </el-option>
            </el-select>
          </el-form-item>

          <el-form-item>
            <div class="d-ib font-table" slot="" style="margin-left: -22%">警衔与文职级别：</div>
            <el-input v-model="form.jxywzjbdm"style="width: 180px"></el-input>
            <div class="d-ib font-table" slot="" style="margin-left: 13px">执勤民警类别：</div>
            <el-select v-model="form.zqmjlbdm" style="width: 180px" placeholder="请选择">
              <el-option label="身份证" value="0"></el-option>
              <el-option label="警官证" value="1"></el-option>
              <el-option label="未知" value="2"></el-option>
            </el-select>
          </el-form-item>

          <el-form-item>
            <div class="d-ib font-table" slot="" style="margin-left: -25%">公安机关部门类别：</div>
            <el-input v-model="form.gajgbmlbdm" style="width: 180px"></el-input>
            <div class="d-ib font-table"style="margin-left: 40px">身份号码：</div>
            <el-input v-model="form.gmsfhm" style="width: 180px"></el-input>
          </el-form-item>

          <el-form-item>
            <div class="d-ib font-table" slot="" style="margin-left: -17%">籍贯省市县：</div>
            <el-input v-model="form.jgssxdm" style="width: 180px"></el-input>
            <div class="d-ib font-table"style="margin-left: 69px">学历：</div>
            <!--<el-input v-model="form.xldm" style="width: 180px"></el-input>-->
            <el-select v-model="form.xldm" style="width: 180px" placeholder="请选择国籍" filterable>
              <el-option label="" value="">--请选择学历--</el-option>
              <el-option
                      v-for="item in optionsXl"
                      :key="item.value"
                      :label="item.content"
                      :value="item.id">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item>
            <div class="d-ib font-table" slot="label">婚姻状况：</div>
            <!--<el-input v-model="form.hyzkdm" style="width: 180px"></el-input>-->
            <el-select v-model="form.hyzkdm" style="width: 180px" placeholder="请选择国籍" filterable>
              <el-option label="" value="">--请选择婚姻状况--</el-option>
              <el-option
                      v-for="item in optionsHyzk"
                      :key="item.value"
                      :label="item.content"
                      :value="item.id">
              </el-option>
            </el-select>
            <div class="d-ib font-table"style="margin-left: 40px">政治面貌：</div>
            <!--<el-input v-model="form.zzmmdm" style="width: 180px"></el-input>-->
            <el-select v-model="form.zzmmdm" style="width: 180px" placeholder="请选择国籍" filterable>
              <el-option label="" value="">--请选择政治面貌--</el-option>
              <el-option
                      v-for="item in optionsZzmm"
                      :key="item.value"
                      :label="item.content"
                      :value="item.id">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item>
            <div class="d-ib font-table" slot="label">地址名称：</div>
            <el-input v-model="form.dzmc" style="width: 180px"></el-input>
            <div class="d-ib font-table"style="margin-left: 12px">公安机关名称：</div>
            <el-input v-model="form.gajgmc" style="width: 180px"></el-input>
          </el-form-item>
          <div class="mb-14">
            <b>勤务装备</b>
          </div>
          <el-form-item>
            <div class="d-ib font-table" slot="label" >类型：</div>
            <el-input v-model="form.qwzbLx" style="width: 180px"></el-input>
            <div class="d-ib font-table" style="margin-left: 40px">地球经度：</div>
            <el-input v-model="form.qwzbDqjd"style="width: 180px"></el-input>
          </el-form-item>
          <el-form-item>
            <div class="d-ib font-table" slot="label" >地球纬度：</div>
            <el-input v-model="form.qwzbDqwd" style="width: 180px"></el-input>
          </el-form-item>
        </el-form>

      </div>
      <div class="d-f jc-c">
        <div v-if="dialog.type=='details'">
          <el-button
                  class="button-cancel"
                  @click="dialog.open = false">关  闭
          </el-button>
        </div>
        <div v-if="dialog.type=='add'">
          <el-button
                  class="button-cancel"
                  @click="cancel()">取 消
          </el-button>
          <el-button
                  class="button-submit mr58"
                  @click="add()">确 定a
          </el-button>
        </div>
        <div v-if="dialog.type=='edit'">
          <el-button
                  class="button-cancel"
                  @click="cancel()">取 消
          </el-button>
          <el-button
                  class="button-submit mr58"
                  @click="edit()">确 定
          </el-button>
        </div>
      </div>
    </el-dialog>

  </div>
</template>

<script>
    import Title from "../../components/Title";
    import CustomTable from "../../components/CustomTable";

    export default {
        name: "chry",
        components: { Title, CustomTable },
        data () {
            return {
                optionsXb:{},
                optionsZjdm:{},
                optionsMz:{},
                optionsGj:{},
                optionsHyzk:{},
                optionsXl:{},
                optionsZzmm:{},
                flag:false,
                fileList: [],
                total: 0,
                pagination: {},

                dialog: {
                    title: '新增方案',
                    open: false,
                    type: 'add',//'edit','add','details'
                },
                form: {
                    xm: ''
                },
                tableData: [

                ],
                columns: [
                    {
                        key: 'xm',
                        label: '姓名'
                    },
                    {
                        key: 'jybh',
                        label: '警员编号'
                    },
                    // {
                    //     key: 'xbdm',
                    //     label: '性别'
                    // },
                    // {
                    //     key: 'jgssxdm',
                    //     label: '籍贯省市县代码'
                    // },
                    // {
                    //     key: 'mzdm',
                    //     label: '民族'
                    // },

                    {
                        key: 'gajgmc',
                        label: '公安机关名称'
                    },
                    {
                        key: 'dzmc',
                        label: '地址名称'
                    },
                    {
                        key: 'gmsfhm',
                        label: '公民身份号码'
                    },
                    {
                        key: 'options',
                        label: '操作',
                        width: '240px',
                        slot: true
                    }
                ],
            }
        },
        mounted () {
            this.selectData();
        },
        methods: {
            selectData() {
                let optionsXb = new Array();
                let optionsZjdm = new Array();
                let optionsMz = new Array();
                let optionsGj = new Array();
                let optionsHyzk = new Array();
                let optionsXl = new Array();
                let optionsZzmm = new Array();
                this.axios.post('t-dictionary/selectList', null
                ).then((res) => {
                    if(res.code == '1'){
                    for (var obj in res.data) {
                        if(res.data[obj].type == 'XB'){
                            optionsXb.push(res.data[obj]);
                        }
                        if(res.data[obj].type == 'ZJDM'){
                            optionsZjdm.push(res.data[obj]);
                        }
                        if(res.data[obj].type == 'MZ'){
                            optionsMz.push(res.data[obj]);
                        }
                        if(res.data[obj].type == 'GJ'){
                            optionsGj.push(res.data[obj]);
                        }
                        if(res.data[obj].type == 'HYZK'){
                            optionsHyzk.push(res.data[obj]);
                        }
                        if(res.data[obj].type == 'XL'){
                            optionsXl.push(res.data[obj]);
                        }
                        if(res.data[obj].type == 'ZZMM'){
                            optionsZzmm.push(res.data[obj]);
                        }
                    }
                    this.optionsXb = optionsXb;
                    this.optionsZjdm = optionsZjdm;
                    this.optionsMz = optionsMz;
                    this.optionsGj = optionsGj;
                    this.optionsHyzk = optionsHyzk;
                    this.optionsXl = optionsXl;
                    this.optionsZzmm = optionsZzmm;

                }
            }).catch((error) => {
                    this.$message({
                    message: '数据查询失败！'+error,
                    type: 'error',
                });
            });
            },
            paginationChange (e) {
                this.pagination = e;
                this.getList(this.pagination.pageNum, this.pagination.pageSize);
            },
            getList (page, limit) {
                this.axios.post('/dxhd-abry-mj/selectPage', {
                    current: page,
                    size: limit,
                    entity: {
                        xm: this.form.xms || '',
                        jybh: this.form.jybhs || ''
                    }

                }).then((res) => {
                    //列表
                    this.tableData = res.data.records;
                this.total = res.data.total;
            }).catch((error) => {
                    console.log(error);
            });
            },
            onSubmit () {
                this.getList(this.pagination.pageNum, this.pagination.pageSize);
            },
            openOptions (scope,params) {
                console.info(scope);
                this.dialog.type = params
                if (params == 'add') {
                    this.flag=false;
                    this.dialog.title = '新增'
                    this.form={}
                }
                if (params == 'edit') {
                    this.flag=false;
                    this.dialog.title = '编辑'
                    this.form=scope.data;
                }
                if (params == 'details') {
                    this.flag=true;
                    this.dialog.title = '详情'
                    this.form=scope.data;
                }
                this.dialog.open = true
            },


            //根据id删除
            getDetail(id) {
                this.axios.post('/dxhd-abry-mj/removeById', {
                    zqmjbz: id || 4588988
                }).then((res) => {
                    this.$message({
                    type: 'success',
                    message: '删除成功!'
                });
                this.onSubmit();
            }).catch((error) => {
                    this.$message({
                    type: 'info',
                    message: '删除失败'
                });
            });
            },

            add(){
                this.axios.post('/dxhd-abry-mj/save', this.form).then((res) => {
                    this.$message({
                    type: 'success',
                    message: '保存成功!'
                });
                this.dialog.open = false
                this.onSubmit();
            }).catch((error) => {
                    this.$message({
                    type: 'info',
                    message: '保存失败'
                });
            });
            },

            edit(){
                this.axios.post('/dxhd-abry-mj/updateById', this.form).then((res) => {
                    this.$message({
                    type: 'success',
                    message: '保存成功!'
                });
                this.dialog.open = false

            }).catch((error) => {
                    this.$message({
                    type: 'info',
                    message: '保存失败'
                });
            });
            },

            deleteDate(row) {
                this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '关闭',
                    type: ''
                }).then(() => {
                    this.getDetail(row.data.zqmjbz);

            }).catch(() => {
                    this.$message({
                    type: 'info',
                    message: '已取消删除'
                });
            });
            },
            cancel(){
                this.onSubmit();
                this.dialog.open = false;

            }


        }
    }
</script>

<style lang="scss">
  .hdda-box {
    .mb-14 {
      margin-bottom: 14px;
    }

    .mr111 {
      margin-right: 111px;
    }

    .mr58 {
      margin-right: 58px;
    }
    .input {
      width: 205px !important;
    }
  }
</style>



